package main

import (
	"os"

	fzap "github.com/mars/third_part/fork/zap"
	"github.com/mars/third_part/fork/zap/zcore"
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

func main() {
	// newCallerEncoder()
	consoleEncoder()
	prettyEncoder()
}

func newCallerEncoder() {
	l, err := zap.NewDevelopment()
	if err != nil {
		panic(err)
	}
	l.Info("saasd", zap.String("key", "value"))
}

func consoleEncoder() {
	config := zap.NewProductionEncoderConfig()
	config.EncodeTime = zapcore.TimeEncoderOfLayout(zcore.StandarTime)
	config.EncodeLevel = zcore.UppercaseLevelEncoder
	config.EncodeCaller = zapcore.ShortCallerEncoder // NO
	config.CallerKey = "C"
	encoder := zapcore.NewConsoleEncoder(config)

	core := zapcore.NewCore(encoder, os.Stderr, zap.DebugLevel)
	logger := zap.New(core, zap.WithCaller(true))
	logger.Info("hello world", zap.String("traceId", "xx12231"))
	// logger.Sugar().With(zap.String("tarcke", "xxxxxxxx")).Infof("consyole hello world: %s", "xxx")
}

func prettyEncoder() {
	config := zap.NewProductionEncoderConfig()
	config.EncodeTime = zapcore.TimeEncoderOfLayout(zcore.StandarTime)
	config.EncodeLevel = zcore.UppercaseLevelEncoder
	encoder := zcore.NewPrettyEncoder(config)

	core := zapcore.NewCore(encoder, os.Stderr, zap.DebugLevel)
	logger := zap.New(core, zap.WithCaller(true), zap.AddCallerSkip(2))
	// logger.Info("hello world", zap.String("traceId", "xx12231"))

	sugar := fzap.Sugar(logger)
	sugar.Log(zap.DebugLevel, "hello world", nil, []zap.Field{zap.String("traceId", "1231")})
}
